﻿namespace UnitTest.Dxp.Core2

open System
open Microsoft.VisualStudio.TestTools.UnitTesting
open Lib.Dxp.Core.Reflect


type IZ() as self = 
    member val Id : int = 0         with get, set
    member val Name : string option = None   with get, set
    abstract PropGet : unit -> string []
    default x.PropGet() = Properties(self).Names


type I() = 
    inherit IZ()
    member val Ida : int = 0            with get, set
    member val IdaXXX : int = 0         with get, set


[<TestClass>]
type UnitTest_DxpCore() = 
    
    [<TestMethod>]
    member x.serial () = 
        let i = I ( Id = 1, Name = Some "xxx" )
        let access = Properties(i)
        let x = Some "123"
        access.set "Name" i x
        Assert.AreEqual(spp x, spp i.Name)

    [<TestMethod>]
    member x.SetterInt () = 
        let i = I ( Id = 1, Name = Some "xxx" )
        let access = Properties(i)
        let x = 11
        access.set "Ida" i x
        Assert.AreEqual(spp x, spp <| access.get "Ida" i)

    [<TestMethod>]
    member x.GetterTest () = 
        let i = I ( Id = 1, Name = Some "xxx" )
        let access = Properties(i)
        Assert.AreEqual(Some "xxx", access.get "Name" i)
        Assert.AreEqual(1, access.get "Id" i)
        Assert.AreEqual(0, access.get "IdaXXX" i)

    [<TestMethod>]
    member x.AutoCollectChildPropNames () = 
        let i = I ( Id = 1, Name = Some "xxx" )
        let testVal = Properties(i).Names 
        Assert.AreEqual(sprintf "%A" [|"Ida"; "IdaXXX"; "Id"; "Name"|], sprintf "%A" testVal)
        Assert.AreEqual("I", Properties(i).TypeName)
